<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //使用组合继承的方式，继承父构造函数的属性和方法
      //公共的部分放在原型上 大家都可以用
      function Father(uname, age, gender) {
        this.uname = uname

        this.age = age

        this.gender = gender
      }

      Father.prototype.money = function () {
        console.log('赚了一个小目标')
      }
      //属性继承
      function Son(uname, age, gender) {
        //改变this指向，从之前的father重新指向为son
        Father.call(this, uname, age, gender)
      }
      // const son = new Son('小张', 18, '男')
      // console.log(son)

      //son通过原型来继承father
      Son.prototype = new Father()
      //指回原来的构造函数
      Son.prototype.constructor = Son
      // 方法继承
      Son.prototype.smoke = function () {
        console.log('我会抽烟')
      }
      const son = new Son('小张', 18, '男')
      console.log(son)
      console.log(Son.prototype)
      son.smoke()
    </script>
  </body>
</html>
